package com.cheney.demo.controller;

import com.cheney.log.annotation.AuditLog;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

/**
 * @author si.chen
 * @date 2021/1/21 11:46
 */
@RestController
@RequestMapping("/test")
public class TestController {

    @GetMapping("/cs")
    @AuditLog(operation = "cs")
    public String cs() {
        CompletableFuture.supplyAsync(() -> {
            try {
                TimeUnit.SECONDS.sleep(5);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("supplyAsync is ok");
            return "CompletableFuture";
        }).whenComplete((k,v)->{
            System.out.println("whenComplete is ok");
        });
        return "ok";
    }

    @GetMapping("/cs2")
    public String cs2() throws Exception {
        int n = 10 / 0;
        return "ok";
    }

    @GetMapping("/cs3")
    public void cs3(HttpServletResponse response) throws Exception {
        response.setHeader("aa","11");
        response.sendRedirect("https://sandbox-portal.connect.aig.com.cn/mall/Home/Pay/toPay");
    }
}
